<template>
  <div class="main_box">
    <el-row>
      <el-col :span="12">
        <Crumbs></Crumbs>
      </el-col>
      <el-col :span="12">
        <div class="opration_wrap">
          <el-button type="primary" icon="fa fa-mail-forward" @click="returnList">返回</el-button>
        </div>
      </el-col>
    </el-row>
    <div class="add_wrap">
      <div class="tit">
        <h2>基础信息</h2>
      </div>
      <el-form :model="addForm" ref="addForm" label-width="200px" :rules="roleRules">
        <el-row>
          <el-form-item label="字典类型名：" prop="typeName" >
            <el-input v-model="addForm.typeName"></el-input>
          </el-form-item>
          <el-form-item label="备注：" prop="remark" >
            <el-input v-model="addForm.remark"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <el-button type="primary" @click="sureClick">保 存</el-button>
            <el-button @click="returnList">取 消</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
  import * as validators from "@/utils/validators"
  import * as message from "@/constants/message"
  import Crumbs from "@/components/Crumbs"
  import Region from "@/components/Region"
  import Map from "@/components/Map"
  export default{
    data(){
      return {
        addForm:{
          remark: "",
          typeName: "",
        },
        disabled:"",
        roleRules: {
          typeName: [
            { required: true, message: "请输入字典类型名", trigger: "blur" }
          ],
          remark: [
            { required: false, message: "请输入字典备注", trigger: "blur" }
          ],
        }
      }
    },
    components: {
      Crumbs,
      Region
    },
    methods: {
      int(){
      },
      sureClick() {
        this.$refs.addForm.validate(valid => {
          if (valid) {
            this.$confirm(message.MSG_CONFIRM_SAVE_ALTER, message.TITLE_PROMPT, {})
              .then(() => {
                this.addDictType();
              });
          }
        })
      },
      addDictType() {
        let data = {
          typeName: this.addForm.typeName,
          remark: this.addForm.remark,
        };
        this.$Post(this.$Config.api.dictTypeAdd, data)
          .then(data => {
            this.$notify.success({
              title: message.TITLE_SUCCESS,
              message: message.MSG_ACTION_SUCCESS
            });
            this.returnList();
          })
          .catch(error => {
            if (error.msg) {
              this.$notify.error({
                title: message.TITLE_ERROR,
                message: error.msg
              });
            }
          })
      },

      returnList(){
        this.$store.dispatch('delView', this.$route);
        this.$router.push({path: '/sys/dictTypeManagement'})
      }
    },

    mounted(){
      this.int();
    }
  }
</script>
<style lang="scss" src="@/assets/css/views/add.scss" scope>
</style>
